import json
import pandas as pd
import os

root = os.path.dirname(__file__)
datas = {
    "classes": [],
    "students": [],
}
for i in datas:
    path = os.path.join(root, f"{i}.csv")
    df = pd.read_csv(path, index_col="index")
    keys = df.columns
    for index, row in df.iterrows():
        data = {}
        for key in keys:
            data[key] = row[key]
            if key == "classid" and not isinstance(data[key], list):
                data[key] = [data[key]]
        datas[f"{i}"].append(data)
path = os.path.join(root, "datas.json")
with open(path, "w+", encoding="utf-8") as f:
    json.dump(
        datas,
        f,
        ensure_ascii=False,
        indent=2,
    )
